/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin			*/
/*	Project:	GlbCloud			*/
/*	Author:		gong_libin			*/
/*	Date:		2012_01_09			*/
/*	File:		MrNet.h				*/
/********************************************************/

#ifndef _MRNET_H
#define	_MRNET_H

#include "MrGlobal.h"
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/resource.h>
#include <unistd.h>
#include <fcntl.h>

#define	MR_URL					22

#define	MR_SEC					1
#define	MR_USEC					500000

#define	MR_TIMEOUT				3

#define	MR_SOCK_MAX				10000
#define	MR_SOCK_BUF				1048576

#define	MR_SOCK_DGRAM				SOCK_DGRAM
#define	MR_SOCK_STREAM				SOCK_STREAM

class CMrNet
{
public:
	CMrNet();
	virtual ~CMrNet();

	void MrNetClose();
	int MrNetGetSocket();
	int MrNetSetNonBlock();
	int MrNetSetReuseAddr();
	int MrNetOpen(int iType);
	int MrNetLimit(UINT uiTotal);
	char* MrNetUrl(char* pszUrl);
	int MrNetSetSndBuf(UINT uiSize);
	int MrNetSetRcvBuf(UINT uiSize);
	void MrNetSetSocket(int iSocket);
	void MrNetSetTimeOut(int iSec, int iUsec);

	virtual int MrNetSend(UCHAR* puszPacket, int iLength) { return MR_SUCCESS; }
	virtual int MrNetRecv(UCHAR* puszPacket, int iLength) { return MR_SUCCESS; }
	virtual int MrNetSendAll(UCHAR* puszPacket, int iLength) { return MR_SUCCESS; }
	virtual int MrNetRecvAll(UCHAR* puszPacket, int iLength) { return MR_SUCCESS; }

	virtual int MrNetInitSend(char* pszUrl) { return MR_SUCCESS; }
	virtual int MrNetInitRecv(char* pszUrl) { return MR_SUCCESS; }
	virtual int MrNetInitSend(struct sockaddr_in* pstAddr) { return MR_SUCCESS; }
	virtual int MrNetInitRecv(struct sockaddr_in* pstAddr) { return MR_SUCCESS; }
	virtual int MrNetInitSend(char* pszAddress, char* pszPort) { return MR_SUCCESS; }
	virtual int MrNetInitRecv(char* pszAddress, char* pszPort) { return MR_SUCCESS; }

protected:
	int m_iSocket;

private:

};

#endif /* _MRNET_H */
